var t = require("../../../mybehaviors/location/location"), a = getApp();

Page({
    behaviors: [ t ],
    data: {
        showServicePopup: !1,
        carousels: [],
        cservice: {},
        store_info: {},
        recommand_obj_list: [],
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        listData: [],
        networkLoading: !1,
        sort_order_field: "",
        sort_order_by: ""
    },
    onLoad: function(t) {
        var a = this;
        this.getGoodsList(), this._getLocation(function(t, e) {
            a.setData({
                address: t.address,
                city: t.address_component.city ? t.address_component.city : t.address_component.province,
                point: e
            }), a.getData();
        });
    },
    openService: function() {
        this.setData({
            showServicePopup: !this.data.showServicePopup
        });
    },
    getData: function() {
        var t = this, e = a.qqMapTransBMap(this.data.point.lng, this.data.point.lat), o = a.getNetAddresss("plugin.reserve-simple.frontend.index.get-data");
        a._getNetWork({
            url: o,
            data: {
                lat: e.lat,
                lng: e.lng
            },
            success: function(e) {
                var o = e.data;
                if (1 != o.result) return a.tips(o.msg);
                console.log(o), t.setData({
                    cservice: o.data.cservice,
                    carousels: o.data.carousels,
                    store_info: o.data.store_info,
                    recommand_obj_list: o.data.recommand_obj_list
                });
            }
        });
    },
    gotoUserDe: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageF/timeAppointment/AppointmentUserDe/AppointmentUserDe?id=" + a
        });
    },
    setSort: function(t) {
        this.setData({
            sort_order_field: t.detail.order_field,
            sort_order_by: t.detail.order_by
        }), this.getGoodsList();
    },
    initData: function() {
        this.setData({
            page: 1,
            total_page: 0,
            isLoadMore: !0,
            networkLoading: !1
        });
    },
    getGoodsList: function() {
        var t = this;
        this.initData();
        var e = a.getNetAddresss("plugin.reserve-simple.frontend.goods.search-goods"), o = {};
        "" != this.data.sort_order_field && (o.order_field = this.data.sort_order_field), 
        "" != this.data.sort_order_by && (o.order_by = this.data.sort_order_by), a._getNetWork({
            url: e,
            data: o,
            success: function(e) {
                var o = e.data;
                if (1 != o.result) return a.tips(o.msg);
                console.log(o), t.data.total_page = o.data.last_page, t.data.total_page || (t.data.total_page = 0), 
                t.setData({
                    listData: o.data.data,
                    networkLoading: !0
                });
            }
        });
    },
    gotoSearch: function() {
        wx.navigateTo({
            url: "/packageF/timeAppointment/timeAppointment_search/timeAppointment_search"
        });
    },
    gotoRecommend: function() {
        wx.navigateTo({
            url: "/packageF/timeAppointment/timeAppointment_search/timeAppointment_search?status=2"
        });
    },
    tolocation: function() {
        var t = getCurrentPages(), a = t[t.length - 1], e = "/".concat(a.route, "?page_id=").concat(this.data.page_id);
        wx.setStorageSync("diyurl", e), wx.navigateTo({
            url: "/packageC/o2o/o2oLocation/o2oLocation?tag=diy"
        });
    },
    goToAdress: function() {
        var t = this.data.store_info.lat, e = this.data.store_info.lng, o = this.data.store_info.name, s = a.BMapTransqqMap(parseFloat(e), parseFloat(t));
        wx.openLocation({
            latitude: s.lat,
            longitude: s.lng,
            scale: 18,
            name: o
        });
    },
    tapUrl: function(t) {
        var a = t.currentTarget.dataset.url;
        if ("" == a) return !1;
        try {
            wx.navigateTo({
                url: a
            });
        } catch (t) {
            console.log(t);
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    _getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page += 1;
            var e = {
                page: this.data.page
            };
            "" != this.data.sort_order_field && (e.order_field = this.data.sort_order_field), 
            "" != this.data.sort_order_by && (e.order_by = this.data.sort_order_by);
            var o = a.getNetAddresss("plugin.reserve-simple.frontend.goods.search-goods");
            a._postNetWork({
                url: o,
                data: e,
                success: function(a) {
                    var e = a.data;
                    if (t.data.isLoadMore = !0, 1 === e.result) {
                        var o = t.data.listData.concat(e.data.data);
                        t.setData({
                            listData: o
                        });
                    } else t.data.page = t.data.page - 1, t.data.isLoadMore = !1;
                }
            });
        }
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {}
});